package gwt.coonay.client;

import com.google.gwt.core.client.JavaScriptObject;

public class HomeData extends JavaScriptObject {
	// Overlay types always have protected, zero argument constructors.
	protected HomeData() {
	};

	public final native String getGmail() /*-{ return this.gmail; }-*/;

	public native static void getJson(int requestId, String url, Home handler) /*-{
	   var callback = "callback" + requestId;
	   
	   var script = document.createElement("script");
	   script.setAttribute("src", url+callback);
	   script.setAttribute("type", "text/javascript");

	   window[callback] = function(jsonObj) {
	     handler.@com.google.gwt.sample.stockwatcher.client.StockWatcher::handleJsonResponse(Lcom/google/gwt/core/client/JavaScriptObject;)(jsonObj);
	     window[callback + "done"] = true;
	   }
	   
	   // JSON download has 1-second timeout
	   setTimeout(function() {
	     if (!window[callback + "done"]) {
	       handler.@com.google.gwt.sample.stockwatcher.client.StockWatcher::handleJsonResponse(Lcom/google/gwt/core/client/JavaScriptObject;)(null);
	     } 

	     // cleanup
	     document.body.removeChild(script);
	     delete window[callback];
	     delete window[callback + "done"];
	   }, 1000);
	   
	   document.body.appendChild(script);
	}-*/;
}
